package com.xyazm.order.remote;


import com.xyazm.common.core.JsonResult;
import com.xyazm.common.utils.CheckResultUtil;
import com.xyazm.order.exception.OrderBizException;
import com.xyazm.order.exception.OrderErrorCodeEnum;
import com.xyazm.pay.api.IPayApi;
import com.xyazm.pay.domain.dto.PayOrderDTO;
import com.xyazm.pay.domain.param.PayOrderParam;
import com.xyazm.pay.domain.param.PayRefundParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * 支付服务远程调用接口
 * @author xuyou
 * 2022-12-06 22:41
*/
@Component
public class PayRemote {

    /**
     * 支付服务
     */
    @DubboReference(version = "1.0.0", retries = 0)
    private IPayApi payApi;

    /**
     * 调用支付系统进行预支付下单
     * @param payOrderRequest
     */
    public PayOrderDTO payOrder(PayOrderParam payOrderRequest) {
        JsonResult<PayOrderDTO> jsonResult = payApi.payOrder(payOrderRequest);
        CheckResultUtil.checkResult(jsonResult,"支付订单");
        return jsonResult.getData();
    }

    /**
     * 调用支付系统执行退款
     * @param payRefundParam
     */
    public void executeRefund(PayRefundParam payRefundParam) {
        JsonResult<Void> jsonResult = payApi.executeRefund(payRefundParam);
        CheckResultUtil.checkResult(jsonResult,"订单退款");
    }

}
